<?php

namespace app\api\hook;



use app\common\model\User;
use Curl\Curl;

class Sms
{
    public function run($sms)
    {
        require_once ROOT_PATH.'vendor/php-curl-class/php-curl-class/src/Curl/Curl.php';
        $account = $sms->account;
        $content = $sms->code;
        $name = '河南繁星心道';
        if ($sms->event == 'register'){
            //$MessageContent = "【{$store->name}】,您的注册验证码为{$content},请勿泄露他人,若非本人操作,请忽略此信息";
            $MessageContent = "【{$name}】,您已注册完成,账号为:{$account},密码为:123456,请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif($sms->event == 'resetpwd') {
            $MessageContent = "【{$name}】,您正在修改密码,验证码为{$content},请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif($sms->event == 'changemobile') {
            $MessageContent = "【{$name}】,您正在修改手机号,验证码为{$content},请勿泄露他人,若非本人操作,请忽略此信息";
        } elseif ($sms->event == 'pay_pwd'){
            $MessageContent = "【{$name}】,您正在修改支付密码,验证码为{$content},请勿泄露他人,若非本人操作,请忽略此信息";
        }elseif ($sms->event == 'set_pay_pwd'){
            $MessageContent = "【{$name}】,您正在设置支付密码,验证码为{$content},请勿泄露他人,若非本人操作,请忽略此信息";
        }

        $api = "http://182.92.174.25:8513/sms/Api/Send.do";
        $data = [
            'SpCode'=>'1444',//企业编号
            'LoginName'=>'zhilan',//用户名称JHC1
            'Password'=>'121212',//用户密码
            'MessageContent'=>$MessageContent,//短信内容,最大700个字符
            'UserNumber'=>$sms->mobile,//手机号码
        ];

        $curl = new Curl();
        $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
        $curl->post($api,$data);
        $res = $curl->response;

        $result = strpos($res, 'result=0');
        return true;

    }
}